class Solution {
public:
    vector<vector<int>> matrixReshape(vector<vector<int>>& nums, int r, int c) {
        int row=nums.size();
        int col=nums[0].size();
        if(row*col!=r*c){return nums;}
        vector<vector<int>>ans;
        vector<int>tmp;
        for(int i=0;i<row;i++){
            for(int j=0;j<col;j++){
                tmp.push_back(nums[i][j]);
                if(tmp.size()==c){ans.push_back(tmp);tmp.clear();}
            }
        }
        return ans;
    }
};